inflect
customizable inflections for nodejs
NOTE: 0.3.2 was accidentally unpublished from the server and npm doesn't allow me to publish it back. Please upgrade to 0.3.3
Installation
npm install i
Usage
Require the module before using
var inflect = require('i')();
All the below api functions can be called directly on a string
inflect.titleize('messages to store')
'messages to store'.titleize
only if true
is passed while initiating
var inflect = require('i')(true);
Pluralize
inflect.pluralize('person');
inflect.pluralize('octopus');
inflect.pluralize('Hat');
Singularize
inflect.singularize('people');
inflect.singularize('octopi');
inflect.singularize('Hats');
Camelize
inflect.camelize('message_properties');
inflect.camelize('message_properties', false);
Underscore
inflect.underscore('MessageProperties');
inflect.underscore('messageProperties');
Humanize
inflect.humanize('message_id');
Dasherize
inflect.dasherize('message_properties');
inflect.dasherize('Message Properties');
Titleize
inflect.titleize('message_properties');
inflect.titleize('message properties to keep');
Demodulize
inflect.demodulize('Message.Bus.Properties');
Tableize
inflect.tableize('MessageBusProperty');
Classify
inflect.classify('message_bus_properties');
Foreign key
inflect.foreign_key('MessageBusProperty');
inflect.foreign_key('MessageBusProperty', false);
Ordinalize
inflect.ordinalize( '1' );
Custom rules for inflection
Custom plural
We can use regexp in any of these custom rules
inflect.inflections.plural('person', 'guys');
inflect.pluralize('person');
inflect.singularize('guys');
Custom singular
inflect.inflections.singular('guys', 'person')
inflect.singularize('guys');
inflect.pluralize('person');
Custom irregular
inflect.inflections.irregular('person', 'guys')
inflect.pluralize('person');
inflect.singularize('guys');
Custom human
inflect.inflections.human(/^(.*)_cnt$/i, '$1_count');
inflect.humanize('jargon_cnt');
Custom uncountable
inflect.inflections.uncountable('oil')
inflect.pluralize('oil');
inflect.singularize('oil');
Contributors
Here is a list of Contributors
TODO
I accept pull requests and guarantee a reply back within a day
License
MIT/X11
Bug Reports
Report here. Guaranteed reply within a day.
Contact
Pavan Kumar Sunkara (pavan.sss1991@gmail.com)
Follow me on github, twitter